package com.google.android.material.transformation;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewTreeObserver.OnPreDrawListener;
import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior;
import androidx.core.view.ViewCompat;
import java.util.List;
import o.aru;

public abstract class ExpandableBehavior extends Behavior<View> {
    private int ॱ = 0;

    protected abstract boolean ˋ(View view, View view2, boolean z, boolean z2);

    public abstract boolean ॱ(CoordinatorLayout coordinatorLayout, View view, View view2);

    public ExpandableBehavior(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    @CallSuper
    public boolean ˎ(CoordinatorLayout coordinatorLayout, final View view, int i) {
        if (!ViewCompat.ˊᐝ(view)) {
            final aru ˊ = ˊ(coordinatorLayout, view);
            if (ˊ != null && ˎ(ˊ.ˏ())) {
                this.ॱ = ˊ.ˏ() ? 1 : 2;
                final int i2 = this.ॱ;
                view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) {
                    final /* synthetic */ ExpandableBehavior ˊ;

                    public boolean onPreDraw() {
                        view.getViewTreeObserver().removeOnPreDrawListener(this);
                        if (this.ˊ.ॱ == i2) {
                            this.ˊ.ˋ((View) ˊ, view, ˊ.ˏ(), false);
                        }
                        return false;
                    }
                });
            }
        }
        return false;
    }

    @CallSuper
    public boolean ˋ(CoordinatorLayout coordinatorLayout, View view, View view2) {
        aru o_aru = (aru) view2;
        if (!ˎ(o_aru.ˏ())) {
            return false;
        }
        this.ॱ = o_aru.ˏ() ? 1 : 2;
        return ˋ((View) o_aru, view, o_aru.ˏ(), true);
    }

    @Nullable
    protected aru ˊ(CoordinatorLayout coordinatorLayout, View view) {
        List ˏ = coordinatorLayout.ˏ(view);
        int size = ˏ.size();
        for (int i = 0; i < size; i++) {
            View view2 = (View) ˏ.get(i);
            if (ॱ(coordinatorLayout, view, view2)) {
                return (aru) view2;
            }
        }
        return null;
    }

    private boolean ˎ(boolean z) {
        boolean z2 = true;
        if (!z) {
            if (this.ॱ != 1) {
                z2 = false;
            }
            return z2;
        } else if (this.ॱ == 0 || this.ॱ == 2) {
            return true;
        } else {
            return false;
        }
    }
}
